package emergency.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xkh.xkh.MyApplication;
import com.xkh.xkh.R;

import java.util.ArrayList;
import java.util.List;

import model.Emergency;

/**
 * Created by Administrator on 2016/4/6.
 */
public class EmergencyshowAdapter extends BaseAdapter {

    List<Emergency> emergencys = new ArrayList<Emergency>();

    public void setEmergencys(List<Emergency> emergencys) {
        this.emergencys = emergencys;
    }

    @Override
    public int getCount() {
        return emergencys.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if (convertView == null)
        {
            convertView = View.inflate(MyApplication.share(), R.layout.item_emergency,null);
            viewHolder = new ViewHolder();
            viewHolder.tv_desc = (TextView) convertView.findViewById(R.id.desc);
            viewHolder.tv_design = (TextView) convertView.findViewById(R.id.id_tv_designLevel);
            viewHolder.tv_down = (TextView) convertView.findViewById(R.id.id_tv_downWaterLevel);
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
            viewHolder.tv_up = (TextView) convertView.findViewById(R.id.id_tv_upWaterLevel);
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.id_tv_gateName);
            convertView.setTag(viewHolder);
        }else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Emergency emergency =  emergencys.get(position);
        viewHolder.tv_up.setText(emergency.getHeightUp()+"");
        viewHolder.tv_down.setText(emergency.getHeightDown()+ "");
        viewHolder.tv_time.setText(emergency.getMeaTime());
        viewHolder.tv_design.setText(emergency.getDesignWaterLevel()+"");
        viewHolder.tv_desc.setText("超过"+(emergency.getHeightUp()-emergency.getDesignWaterLevel())+"厘米");
        viewHolder.tv_name.setText(emergency.getWatergateName());
        return convertView;
    }

    class ViewHolder
    {
        TextView tv_design;
        TextView tv_up;
        TextView tv_down;
        TextView tv_time;
        TextView tv_desc;
        TextView tv_name;
    }


}
